package com.yystar.support.base.task;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yystar.support.base.domain.BaseDomain;

public abstract class AbstractTimerTask extends BaseDomain implements Runnable {
	protected static final Log log = LogFactory.getLog("TimerTaskLog");
	protected long lastExecutionTime;
	protected Date lastExecutionDateTime = new Date();


	public void run() {
		try {
			lastExecutionDateTime = new Date();
			//log.info(getClass().getSimpleName() + " start to load");
			long startTime = System.currentTimeMillis();

			reload();
			lastExecutionTime = System.currentTimeMillis() - startTime;

			//log.info("reloaded " + getClass().getSimpleName() + " took " + lastExecutionTime + "ms");
		} catch (Throwable e) {
			log.error(getClass().getSimpleName() + " failed to load", e);
		}
	}

	protected abstract void reload();

	public long getLastExecutionTime() {
		return lastExecutionTime;
	}

	public Date getLastExecutionDateTime() {
		return lastExecutionDateTime;
	}
	
	
}
